import logging

import pytest

from resource.pom.settings import Settings


class Test:
    app = Settings

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.点击设置-应用-应用管理，点击某一应用')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        device.click(*self.app.apps_item)
        device.refresh_layout()
        device.click_element(device.get_element_by_text('应用管理'))
        device.refresh_layout()
        device.click_element(device.get_element_by_type('ListItem'))

        logging.info('预期结果1.进入应用')
        device.refresh_layout()
        device.assert_text_exist('应用信息')
        device.assert_text_exist('强行停止')
        device.assert_text_exist('存储')

        logging.info('步骤2.点击存储')
        device.click_element(device.get_element_by_text('存储'))
        logging.info('预期结果2.进入存储')
        device.refresh_layout()
        device.assert_text_exist('存储')
        device.assert_text_exist('高级')
        device.assert_text_exist('总计')
        device.assert_text_exist('应用')
        device.assert_text_exist('数据')
        device.assert_text_exist('删除数据')
        device.assert_text_exist('缓存')
        device.assert_text_exist('清空缓存')

        logging.info('步骤3.点击删除数据-确定/清空缓存')
        clear_data = device.get_element_by_text('删除数据')
        clear_cache = device.get_element_by_text('清空缓存')
        device.click_element(clear_data)
        device.refresh_layout()
        device.click_element(device.get_element_by_text('确定'))
        device.click_element(clear_cache)
        logging.info('预期结果3.点击确定可以删除应用的全部数据/清空缓存数据')
        device.refresh_layout()
        device.assert_text_exist('0 B')
